﻿<!--#include file="../inc/common.asp" -->
<!--#include file="waputil.asp" -->
<%
  response.contentType="text/vnd.wap.wml"
  'response.contentType="text/xml"
  response.charset=DEFAULT_CHARSET
  response.buffer = true  

  'on error resume next

  if not userRightObj.canReply then
    message("您没有回复权限")
  end if

  dim content_id, blogItem, parent_id,parentComment, count, i

  content_id = trim(request("content_id"))
  set blogItem = new BlogItemClass    

  parent_id = trim(request("parent_id"))
  set parentComment = new BlogCommentClass


  if content_id="" then
    message("文章不存在")
    return
  end if
  
  content_id = clng(content_id)
  
  if  blogItem.load(content_id) = false then
    message("文章不存在")
    call closeDB()
    response.end
  end if
  
  if isNumeric(parent_id) then
    parent_id = clng(parent_id)
    if parent_id<>0 then
        parentComment.load(parent_id)
    else
        parent_id=""
    end if   
  else
    parent_id=""   
  end if  
  
%>
<?xml version="1.0" encoding="<%=DEFAULT_CHARSET%>"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapfourm.org/DTD/wml_1.1.xml">
<wml>
<card title="发表评论" newcontext="false" ordered="true">
<%
  if (request("actionType")="doSave") then
    call openDB
    
    dim detail, user_name, rs2
    user_name =  userObj.userName
    if trim(user_name)="" then
        user_name = "[匿名]"
    end if
    detail =  filterHTML2(request("detail"), true)
    set rs2 = Server.CreateObject("ADODB.Recordset")
    sql = " select comment_id, blog_id, content_id,parent_id, detail, user_id,user_name from blog_comments where comment_id=0 "
    rs2.open sql, conn, 1, 3
    rs2.addNew()
    rs2("blog_id") = blogObj.blogId
    rs2("content_id") = content_id
    if isNumeric(parent_id) then
        rs2("parent_id") = parent_id
    else
        rs2("parent_id") = Null
    end if    
    rs2("detail") = detail
    rs2("user_id") = userObj.userId
    rs2("user_name") = userObj.userName
    rs2.update()
    rs2.close()
    set rs2 = nothing

    sql = " update blog_content set reply_count=reply_count+1, update_time=now() where content_id=" & content_id
    conn.execute(sql)
    
    call blogItem.reload(content_id)  
    call blogObj.loadTopCommentsFromDB()
    call blogObj.cache()
    
%>
<p>提交成功！<br/>
[<a href="detail.asp?blog_id=<%=blogItem.blogId%>&amp;content_id=<%=blogItem.itemId%>&amp;pageno_list=<%=request("pageno_list")%>">返回正文</a>]<br/>
[<a href="list.asp?blog_id=<%=blogItem.blogId%>&amp;pageno_list=<%=request("pageno_list")%>">返回<%=HTML2WML(blogObj.blogTitle)%>首页</a>]<br/>
[<a href="list.asp">返回最新文章列表</a>]
</p>
<%
    else
%>
<p>
用户名:<input name="user_name" title="用户名" type="text" format="*M" emptyok="true" value="<%=HTML2WML(userObj.userName)%>" />
回复内容:<input name="comment_detail" title="回复内容" type="text" value="" format="*M" emptyok="false" />
<anchor>[提交]<go href="reply.asp" method="post" accept-charset="<%=DEFAULT_CHARSET%>">
        <postfield name="actionType" value="doSave"/>
        <postfield name="blog_id" value="<%=blogObj.blogId%>"/>
        <postfield name="content_id" value="<%=content_id%>"/>
        <postfield name="parent_id" value="<%=parent_id%>"/>
        <postfield name="username" value="$user_name"/>
        <postfield name="detail" value="$comment_detail"/>
        <postfield name="pageno_list" value="<%=request("pageno_list")%>"/>
    </go></anchor>&nbsp;<anchor>[取消]<prev/></anchor>
</p>
<%
    end if
%>
<%
  writeBlogOptions
%>
</card>
</wml>
<%
  set blogItem = nothing
  closeDB()
  'session.abandon
%>